package com.suning.sawp.service.impl.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.suning.framework.dal.client.DalClient;
import com.suning.sawp.dto.aircondition.AirConditionConstants;
import com.suning.sawp.dto.aircondition.MyCustRequest;
import com.suning.sawp.dto.aircondition.SchemeInfo;
import com.suning.sawp.dto.aircondition.SchemeTempletInfo;
import com.suning.sawp.po.airCondition.AirCondition;
import com.suning.sawp.po.airCondition.AirConditionComm;
import com.suning.sawp.po.airCondition.AirConditionTemplet;
import com.suning.sawp.po.airCondition.AirConditionTempletComm;
import com.suning.sawp.service.util.DateUtils;

/**
 * 已销未提Dao
 *
 * @author 15050769
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service("airConditionDaoService")
public class AirConditionDaoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AirConditionDaoService.class);

    @Resource
    DalClient dalClient;

    private final String AIRCONDITION_QUERYSCHEMEFORCUST = "AIRCONDITION.QUERYSCHEMEFORCUST";

    private final String AIRCONDITION_QUERYMYCUST = "AIRCONDITION.QUERYMYCUST";

    private final String AIRCONDITION_QUERYSCHEMEBYID = "AIRCONDITION.QUERYSCHEMEBYID";

    private final String AIRCONDITION_QUERYSCHEMECOMMLIST = "AIRCONDITION.QUERYSCHEMECOMMLIST";

    private final String AIRCONDITION_QUERYSCHEMETEMPLET = "AIRCONDITION.QUERYSCHEMETEMPLET";

    private final String AIRCONDITION_QUERYTEMPLETCOMMBYID = "AIRCONDITION.QUERYTEMPLETCOMMBYID";

    private final String AIRCONDITION_DELETERECORD = "AIRCONDITION.DELETERECORD";

    private final String AIRCONDITION_QUERYTEMPLETBYID = "AIRCONDITION.QUERYTEMPLETBYID";

    private final String AIRCONDITION_SUBMITCUSTMADE = "AIRCONDITION.SUBMITCUSTMADE";

    private final String AIRCONDITION_ISOVERLIMIT = "AIRCONDITION.ISOVERLIMIT";

    private final String AIRCONDITION_SUBMITSCHEMECOMM = "AIRCONDITION.SUBMITSCHEMECOMM";

    private final String AIRCONDITION_UPDATESCHEME = "AIRCONDITION.UPDATESCHEME";

    private final String AIRCONDITION_DELETESCHEMECOMM = "AIRCONDITION.DELETESCHEMECOMM";

    private final String AIRCONDITION_SUBMITSCHEMETEMPLET = "AIRCONDITION.SUBMITSCHEMETEMPLET";

    private final String AIRCONDITION_UPDATESCHEMETEMPLET = "AIRCONDITION.UPDATESCHEMETEMPLET";

    private final String AIRCONDITION_DELETESCHEMETEMPLETCOMM = "AIRCONDITION.DELETESCHEMETEMPLETCOMM";

    private final String AIRCONDITION_SUBMITSCHEMETEMPLETCOMM = "AIRCONDITION.SUBMITSCHEMETEMPLETCOMM";

    /**
     * 查询客户相关的方案列表
     *
     * @param index
     * @param size
     * @param mobileNum
     * @param cityId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public List<AirCondition> querySchemeForCust(int index, int size, String mobileNum, String cityId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("index", index);
        paramMap.put("size", size);
        paramMap.put("cityCode", cityId);
        paramMap.put("custNum", mobileNum);
        List<AirCondition> resultList;
        try {
            resultList = dalClient.queryForList(AIRCONDITION_QUERYSCHEMEFORCUST, paramMap, AirCondition.class);
        } catch (Exception e) {
            LOGGER.error("querySchemeForCust error ", e);
            return null;
        }
        return resultList;
    }

    /**
     * 根据方案ID查詢客戶資料
     *
     * @param schemeCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public AirCondition querySchemeByID(String schemeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("schemeCode", schemeCode);
        AirCondition airCondition;
        try {
            airCondition = dalClient.queryForObject(AIRCONDITION_QUERYSCHEMEBYID, paramMap, AirCondition.class);
            if(airCondition == null ){
                airCondition = new AirCondition();
            }
        } catch (Exception e) {
            LOGGER.error("querySchemeByID error ,schemeCode :  " + schemeCode, e);
            return null;
        }
        return airCondition;
    }

    /**
     * 
     * 根据方案ID查询商品列表
     *
     * @param schemeCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public List<AirConditionComm> querySchemeCommList(String schemeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("schemeCode", schemeCode);
        List<AirConditionComm> resultList;
        try {
            resultList = dalClient.queryForList(AIRCONDITION_QUERYSCHEMECOMMLIST, paramMap, AirConditionComm.class);
        } catch (Exception e) {
            LOGGER.error("querySchemeCommList error schemeCode :  " + schemeCode, e);
            return null;
        }
        return resultList;
    }

    /**
     * 
     * 根据分公司编码查询对应的模板列表
     *
     * @param branchCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public List<AirConditionTemplet> querySchemeTemplet(String branchCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("branchId", branchCode);
        List<AirConditionTemplet> resultList;
        try {
            resultList = dalClient.queryForList(AIRCONDITION_QUERYSCHEMETEMPLET, paramMap, AirConditionTemplet.class);
        } catch (Exception e) {
            LOGGER.error("querySchemeTemplet error branchCode :  " + branchCode, e);
            return null;
        }
        return resultList;

    }

    /**
     * 
     * 根据模板ID查询模板商品信息
     *
     * @param templetId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public List<AirConditionTempletComm> queryTempletCommById(String templetId) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("templetId", templetId);
        List<AirConditionTempletComm> resultList;
        try {
            resultList = dalClient.queryForList(AIRCONDITION_QUERYTEMPLETCOMMBYID, paramMap,
                    AirConditionTempletComm.class);
        } catch (Exception e) {
            LOGGER.error("queryTempletCommById error templetId :  " + templetId, e);
            return null;
        }
        return resultList;

    }

    /**
     * 
     * 根据模板ID查询模板信息
     *
     * @param templetId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public AirConditionTemplet queryTempletById(String templetId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("templetId", templetId);
        AirConditionTemplet result;
        try {
            result = dalClient.queryForObject(AIRCONDITION_QUERYTEMPLETBYID, paramMap, AirConditionTemplet.class);
            if(result == null){
                result = new AirConditionTemplet();
            }
        } catch (Exception e) {
            LOGGER.error("queryTempletById error templetId :  " + templetId, e);
            return null;
        }
        return result;

    }

    /**
     * 根据条件查询客户接待记录
     *
     * @param myCustRequest
     * @param staffId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public List<AirCondition> queryMyCust(MyCustRequest myCustRequest, String staffId) {
        String zoneName = myCustRequest.getZoneName();
        String custNum = myCustRequest.getCustNum();
        int index = myCustRequest.getIndex();
        String schemeType = myCustRequest.getSchemeType();
        int size = myCustRequest.getSize();
        String status = myCustRequest.getStatus();
        String timeConditon = myCustRequest.getTimeConditon();

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("index", index);
        paramMap.put("size", size);
        paramMap.put("staffId", staffId);

        if (StringUtils.isNotBlank(custNum) && NumberUtils.isNumber(custNum) && custNum.length() == 11) {
            paramMap.put("custNum", custNum);
        } else if (StringUtils.isNotBlank(zoneName)) {
            paramMap.put("zoneName", "%" + zoneName + "%");
        }
        if (StringUtils.isNotBlank(schemeType)) {
            paramMap.put("schemeType", schemeType);
        }
        if (StringUtils.isNotBlank(status)) {
            paramMap.put("status", status);
        }
        if (StringUtils.isNotBlank(timeConditon)) {
            paramMap.put("timeConditon", timeConditon);
        }

        List<AirCondition> resultList;
        try {
            resultList = dalClient.queryForList(AIRCONDITION_QUERYMYCUST, paramMap, AirCondition.class);
        } catch (Exception e) {
            LOGGER.error("queryMyCust error ", e);
            return null;
        }
        return resultList;

    }

    /**
     * 
     * 软删除对应客户的接待记录
     *
     * @param staffId
     * @param schemeCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public boolean deleteRecord(String staffId, String schemeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("schemeCode", schemeCode);
        paramMap.put("staffId", staffId);
        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_DELETERECORD, paramMap);
            if (returnResult == -1) {
                result = false;
            } else {
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("deleteRecord error staffId : " + staffId + ",schemeCode :" + schemeCode, e);
            result = false;
        }
        return result;
    }

    /**
     * 
     * 提交定制客户资料
     *
     * @param airCondition
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public boolean submitCustMade(AirCondition airCondition) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (StringUtils.isNotBlank(airCondition.getOrderTime())) {
            paramMap.put("orderTime",
                    DateUtils.getDateByStr(airCondition.getOrderTime(), DateUtils.ACCURATE_MINUTES_PATTERN));
        }else{
            paramMap.put("orderTime",new Date());
        }
        paramMap.put("staffId", airCondition.getStaffId());
        paramMap.put("custName", airCondition.getCustName());
        paramMap.put("custNum", airCondition.getCustNum());

        paramMap.put("custNumBack", airCondition.getCustNumBack());
        paramMap.put("zoneName", airCondition.getZoneName());
        paramMap.put("address", airCondition.getAddress());
        if (NumberUtils.isNumber( airCondition.getTotalSize())) {
            paramMap.put("totalSize", airCondition.getTotalSize());
        } else {
            paramMap.put("totalSize", "0");
        }
        paramMap.put("sex", airCondition.getSex());

        paramMap.put("custRemark", airCondition.getCustRemark());
        paramMap.put("houseType", airCondition.getHouseType());
        String houseTypeName = getHouseTypeName(airCondition.getHouseType());
        paramMap.put("houseTypeName", houseTypeName);
        if (NumberUtils.isNumber( airCondition.getTotalPrice())) {
            paramMap.put("totalPrice", airCondition.getTotalPrice());
        } else {
            paramMap.put("totalPrice", "0");
        }
        paramMap.put("remark", airCondition.getRemark());

        paramMap.put("brandCode", airCondition.getBrandCode());
        paramMap.put("brandName", airCondition.getBrandName());
        paramMap.put("shoppingCode", airCondition.getShoppingCode());
        paramMap.put("schemeType", AirConditionConstants.AIRCON.SCHEME_TYPE_DINGZHI);

        paramMap.put("status", AirConditionConstants.AIRCON.IN_DINGZHI);
        paramMap.put("cityCode", airCondition.getCityCode());
        paramMap.put("schemeTime", new Date());
        paramMap.put("storeName", airCondition.getStoreName());

        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_SUBMITCUSTMADE, paramMap);
            if (returnResult == -1) {
                result = false;
            } else {
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("submitCustqMade error staffId : " + airCondition.getStaffId(), e);
            result = false;
        }
        return result;
    }

    /**
     * 
     * 检查价格是否超过现价
     *
     * @param commCode
     * @param custNum
     * @param cityId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public Double isOverLimit(String commCode, String custNum, String cityId,String staffId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("commCode", commCode);
        paramMap.put("custNum", custNum);
        paramMap.put("cityCode", cityId);
        paramMap.put("staffId", staffId);
        double minPrice = 0;
        try {
            Map<String, Object> resultMap = dalClient.queryForMap(AIRCONDITION_ISOVERLIMIT, paramMap);
            Object result = resultMap.get("minPrice");
            if (result != null) {
                minPrice = (Double) resultMap.get("minPrice");
            } else {
                return null;
            }
        } catch (Exception e) {
            LOGGER.error("deleteRecord error commCode : " + commCode + ",custNum :" + custNum, e);
            return null;
        }
        return minPrice;
    }

    /**
     * 
     * 提交方案
     *
     * @param airCondition
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public String submitScheme(AirCondition airCondition) {

        Map<String, Object> paramMap = new HashMap<String, Object>();

        if (StringUtils.isNotBlank(airCondition.getOrderTime())) {
            paramMap.put("orderTime",
                    DateUtils.getDateByStr(airCondition.getOrderTime(), DateUtils.ACCURATE_MINUTES_PATTERN));
        }else{
            paramMap.put("orderTime",new Date());
        }
        paramMap.put("staffId", airCondition.getStaffId());
        paramMap.put("custName", airCondition.getCustName());
        paramMap.put("custNum", airCondition.getCustNum());

        paramMap.put("custNumBack", airCondition.getCustNumBack());
        paramMap.put("zoneName", airCondition.getZoneName());
        paramMap.put("address", airCondition.getAddress());
        if (NumberUtils.isNumber( airCondition.getTotalSize())) {
            paramMap.put("totalSize", airCondition.getTotalSize());
        } else {
            paramMap.put("totalSize", "0");
        }
        paramMap.put("sex", airCondition.getSex());

        paramMap.put("custRemark", airCondition.getCustRemark());
        paramMap.put("houseType", airCondition.getHouseType());
        String houseTypeName = getHouseTypeName(airCondition.getHouseType());
        paramMap.put("houseTypeName", houseTypeName);
        if (NumberUtils.isNumber( airCondition.getTotalPrice())) {
            paramMap.put("totalPrice", airCondition.getTotalPrice());
        } else {
            paramMap.put("totalPrice", "0");
        }
        paramMap.put("remark", airCondition.getRemark());

        paramMap.put("brandCode", airCondition.getBrandCode());
        paramMap.put("brandName", airCondition.getBrandName());
        paramMap.put("shoppingCode", airCondition.getShoppingCode());
        if(StringUtils.isBlank(airCondition.getSchemeType()) || !AirConditionConstants.AIRCON.SCHEME_TYPE_DINGZHI.equals(airCondition.getSchemeType())){
            paramMap.put("schemeType",AirConditionConstants.AIRCON.SCHEME_TYPE_NORMAL);
        }else{
            paramMap.put("schemeType", airCondition.getSchemeType());
        }
        
        if(StringUtils.isBlank( airCondition.getStatus())){
            paramMap.put("status", AirConditionConstants.AIRCON.WEIGOUMAI);
        }else{
            paramMap.put("status", airCondition.getStatus());
        }
        paramMap.put("cityCode", airCondition.getCityCode());
        paramMap.put("schemeTime", new Date());
        paramMap.put("storeName", airCondition.getStoreName());

        String result = "";
        try {
            Number returnResult = dalClient.execute4PrimaryKey(AIRCONDITION_SUBMITCUSTMADE, paramMap);
            result = returnResult.toString();
        } catch (Exception e) {
            LOGGER.error("submitCustqMade error staffId : " + airCondition.getStaffId(), e);
        }
        return result;
    }

    /**
     * 
     * 提交保存方案对应的商品信息
     *
     * @param commList
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public boolean submitSchemeComm(List<AirConditionComm> commList) {
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
        for (AirConditionComm item : commList) {
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("schemeCode", item.getSchemeCode());
            paramMap.put("commCode", item.getCommCode());
            paramMap.put("commName", item.getCommName());
            if (NumberUtils.isNumber( item.getPrice())) {
                paramMap.put("price", item.getPrice());
            } else {
                paramMap.put("price", "0");
            }
            paramMap.put("roomName", item.getRoomName());
            paramMap.put("roomCode", item.getRoomCode());
            if (NumberUtils.isNumber(item.getSize())) {
                paramMap.put("size", item.getSize());
            } else {
                paramMap.put("size", "0");
            }
            paramMap.put("positionCode", item.getPositionCode());
            paramMap.put("positionName", item.getPositionName());
            mapList.add(paramMap);
        }
        @SuppressWarnings("unchecked")
        Map<String, Object>[] batchValues = (Map<String, Object>[]) mapList.toArray(new Map[mapList.size()]);
        boolean result = false;
        try {
            int[] rets = dalClient.batchUpdate(AIRCONDITION_SUBMITSCHEMECOMM, batchValues);
            if (rets == null) {
                result = false;
            } else {
                for (int i = 0; i < rets.length; i++) {
                    if (rets[i] < 0) {
                        LOGGER.error("submitSchemeComm error ");
                        return false;
                    }
                }
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("submitSchemeTempletComm error commList : " + commList, e);
        }
        return result;
    }

    /**
     * 
     * 更新方案
     *
     * @param schemeInfo
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public boolean updateScheme(SchemeInfo schemeInfo) {

        Map<String, Object> paramMap = new HashMap<String, Object>();

        paramMap.put("schemeCode", schemeInfo.getSchemeCode());

        if (StringUtils.isNotBlank(schemeInfo.getOrderTime())) {
            paramMap.put("orderTime",
                    DateUtils.getDateByStr(schemeInfo.getOrderTime(), DateUtils.ACCURATE_MINUTES_PATTERN));
        }
        paramMap.put("custName", schemeInfo.getCustName());
        paramMap.put("custNum", schemeInfo.getCustNum());
        paramMap.put("custNumBack", schemeInfo.getCustNumBack());
        paramMap.put("zoneName", schemeInfo.getZoneName());

        paramMap.put("address", schemeInfo.getAddress());
        if (NumberUtils.isNumber(schemeInfo.getTotalSize())) {
            paramMap.put("totalSize", schemeInfo.getTotalSize());
        } else {
            paramMap.put("totalSize", "0");
        }

        paramMap.put("sex", schemeInfo.getSex());
        paramMap.put("custRemark", schemeInfo.getCustRemark());
        paramMap.put("houseType", schemeInfo.getHouseType());

        String houseTypeName = getHouseTypeName(schemeInfo.getHouseType());
        paramMap.put("houseTypeName",houseTypeName);
        if (NumberUtils.isNumber( schemeInfo.getTotalPrice())) {
            paramMap.put("totalPrice", schemeInfo.getTotalPrice());
        } else {
            paramMap.put("totalPrice", "0");
        }
        paramMap.put("remark", schemeInfo.getRemark());
        paramMap.put("brandCode", schemeInfo.getBrandCode());
        paramMap.put("brandName", schemeInfo.getBrandName());

        paramMap.put("shoppingCode", schemeInfo.getShoppingCode());
        if(StringUtils.isBlank(schemeInfo.getSchemeType()) || !AirConditionConstants.AIRCON.SCHEME_TYPE_DINGZHI.equals(schemeInfo.getSchemeType())){
            paramMap.put("schemeType",AirConditionConstants.AIRCON.SCHEME_TYPE_NORMAL);
        }else{
            paramMap.put("schemeType", schemeInfo.getSchemeType());
        }
        paramMap.put("status", schemeInfo.getStatus());

        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_UPDATESCHEME, paramMap);
            if (returnResult != 1) {
                result = false;
            } else {
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("updateScheme error schemeInfo : " + schemeInfo, e);
        }
        return result;
    }

    private String getHouseTypeName(String houseType) {
        if(StringUtils.isBlank(houseType)){
            return "";
        }
        String[] hix = houseType.split("-");
        String houseTypeName = "";
        if(hix.length > 1){
            houseTypeName = hix[0] +"室" +hix[1]+"厅";
        }
        return houseTypeName;
    }

    /**
     * 
     * 删除方案对应的商品信息
     *
     * @param schemeCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public boolean deleteSchemeComm(String schemeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();

        paramMap.put("schemeCode", schemeCode);

        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_DELETESCHEMECOMM, paramMap);
            if (returnResult == -1) {
                result = false;
            } else {
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("deleteSchemeComm error schemeCode : " + schemeCode, e);
        }
        return result;

    }

    /**
     * 提交模板信息 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param airCondition
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    public String submitSchemeTemplet(AirConditionTemplet airCondition) {
        Map<String, Object> paramMap = new HashMap<String, Object>();

        paramMap.put("houseType", airCondition.getHouseType());
        String houseTypeName = getHouseTypeName(airCondition.getHouseType());
        paramMap.put("houseTypeName", houseTypeName);
        if (NumberUtils.isNumber( airCondition.getTotalPrice())) {
            paramMap.put("totalPrice", airCondition.getTotalPrice());
        } else {
            paramMap.put("totalPrice", "0");
        }
        paramMap.put("remark", airCondition.getRemark());
        paramMap.put("branchId", airCondition.getBranchId());

        paramMap.put("brandCode", airCondition.getBrandCode());
        paramMap.put("brandName", airCondition.getBrandName());
        paramMap.put("shoppingCode", airCondition.getShoppingCode());
        paramMap.put("templetName", airCondition.getTempletName());
        paramMap.put("templetType", airCondition.getTempletType());

        String result = "";
        try {
            Number returnResult = dalClient.execute4PrimaryKey(AIRCONDITION_SUBMITSCHEMETEMPLET, paramMap);
            result = returnResult.toString();
        } catch (Exception e) {
            LOGGER.error("submitSchemeTemplet error staffId : " + airCondition, e);
        }
        return result;
    }

    public boolean submitSchemeTempletComm(List<AirConditionTempletComm> commList) {
        boolean result = false;
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
        for (AirConditionTempletComm item : commList) {
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("templetId", item.getTempletId());
            paramMap.put("commCode", item.getCommCode());
            paramMap.put("commName", item.getCommName());
            if (NumberUtils.isNumber( item.getPrice())) {
                paramMap.put("price", item.getPrice());
            } else {
                paramMap.put("price", "0");
            }
            paramMap.put("roomName", item.getRoomName());
            paramMap.put("roomCode", item.getRoomCode());
            if (NumberUtils.isNumber( item.getSize())) {
                paramMap.put("size", item.getSize());
            } else {
                paramMap.put("size", "0");
            }

            paramMap.put("positionCode", item.getPositionCode());
            paramMap.put("positionName", item.getPositionName());
            mapList.add(paramMap);
        }
        @SuppressWarnings("unchecked")
        Map<String, Object>[] batchValues = (Map<String, Object>[]) mapList.toArray(new Map[mapList.size()]);
        try {
            int[] rets = dalClient.batchUpdate(AIRCONDITION_SUBMITSCHEMETEMPLETCOMM, batchValues);
            if (rets == null) {
                result = false;
            } else {
                for (int i = 0; i < rets.length; i++) {
                    if (rets[i] < 0) {
                        LOGGER.error("submitSchemeTempletComm error ");
                        return false;
                    }
                }
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("submitSchemeTempletComm error commList : " + commList, e);
        }
        return result;
    }

    public boolean updateSchemeTemplet(SchemeTempletInfo schemeInfo) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("templetId", schemeInfo.getTempletId());
        paramMap.put("remark", schemeInfo.getRemark());
        paramMap.put("brandCode", schemeInfo.getBrandCode());
        paramMap.put("brandName", schemeInfo.getBrandName());
        paramMap.put("shoppingCode", schemeInfo.getShoppingCode());

        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_UPDATESCHEMETEMPLET, paramMap);
            if (returnResult == -1) {
                result = false;
            } else {
                result = true;
            }
        } catch (Exception e) {
            LOGGER.error("updateSchemeTemplet error schemeInfo : " + schemeInfo, e);
        }
        return result;

    }

    public boolean deleteSchemeTempletComm(String templetId) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("templetId", templetId);

        boolean result = false;
        try {
            int returnResult = dalClient.execute(AIRCONDITION_DELETESCHEMETEMPLETCOMM, paramMap);
            LOGGER.info("deleteSchemeTempletComm returnResult :" + returnResult + " ,templetId : " + templetId);
            result = true;
        } catch (Exception e) {
            LOGGER.error("deleteSchemeTempletComm error templetId : " + templetId, e);
        }
        return result;
    }

}
